 package com.fix.web;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fix.entity.Users;

@Controller
public class ChatController {
	
	//首页
	@RequestMapping("/")
	public String index() {
		return "login";
	}
	
	@RequestMapping("/room")
	public String room() {
		return "room";
	}
	
	//登录
	@RequestMapping("/login")
	public String login(Users user,HttpServletRequest request) {
		HttpSession session =  request.getSession();		 
		// 获取用户
		if (null != session.getAttribute("loginuser")) {
			//清除旧用户
			session.removeAttribute("loginuser");
		}		
		//随机生产用户ID
		String userId =UUID.randomUUID().toString();
		user.setUid(userId);
		session.setAttribute("loginuser", user);
		//显示
		return "redirect:room";
	}
	
	//下线 --去登录页
	@RequestMapping("/logout")
	public String logout() {
		
		return "login";
	}

}
